package com.red.controller.admin;

import com.red.dto.HomePageQueryDTO;
import com.red.entity.Questions;
import com.red.result.PageResult;
import com.red.result.Result;
import com.red.service.QuestionsService;
import io.swagger.annotations.ApiModelProperty;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController("AdminQuestionsController")
@RequestMapping("/admin/question")
@Slf4j
@CrossOrigin
public class QuestionsController {

    @Autowired
    private QuestionsService questionsService;

    /**
     * 分页查询
     * @return
     */
    @GetMapping
    public Result<PageResult> pageQueryQuestions(HomePageQueryDTO dto) {
        log.info("分页查询数据：{}",dto);
        PageResult pageResult = questionsService.pageQuery(dto);
        return Result.success(pageResult);
    }

    /**
     * 新增题目
     * @param questions
     * @return
     */
    @PostMapping("/insert")
    @ApiModelProperty("新增题目")
    public Result insert(@RequestBody Questions questions){
        questionsService.insertQuestion(questions);
        return Result.success();
    }

    /**
     * 批量删除
     * @param ids
     * @return
     */
    @DeleteMapping("/{ids}")
    @ApiModelProperty("批量删除")
    public Result deleteByIds(@PathVariable List<Long> ids){
        questionsService.deleteByIds(ids);
        return Result.success();
    }

    /**
     * 更改题目
     * @param questions
     * @return
     */
    @PostMapping("/update")
    public Result update(@RequestBody Questions questions){
        log.info("更改信息 = {}",questions);
        questionsService.updateQuestions(questions);
        return Result.success();
    }
}
